package ${package.Controller};


import org.springframework.web.bind.annotation.RequestMapping;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
    @Autowired
    I${entity}Service ${entity?uncap_first}Service;

    @RequestMapping("/{type}")
    public String type(){
        return null;
    }

    @RequestMapping("/listByParams")
    @ResponseBody
    public List<${entity}> listByParams(${entity} ${entity?uncap_first},
                                        @RequestParam(value = "current",required = false,defaultValue = "1") Integer current,
                                        @RequestParam(value = "size",required = false,defaultValue = "10") Integer size){
        return ${entity?uncap_first}Service.listByParams(${entity?uncap_first},current,size);
    }

    @RequestMapping("/listAll")
    @ResponseBody
    public List<${entity}> listAll(){
        return ${entity?uncap_first}Service.list();
    }

    @RequestMapping("/read")
    @ResponseBody
    public ${entity} read(${entity} ${entity?uncap_first}){
        if(StrUtil.isNotEmpty(${entity?uncap_first}.getId())){
            ${entity?uncap_first}=${entity?uncap_first}Service.getById(${entity?uncap_first});
        }
        return ${entity?uncap_first};
    }

    @RequestMapping("/save")
    @ResponseBody
    public Boolean save(${entity} ${entity?uncap_first}){
        return ${entity?uncap_first}Service.saveOrUpdate(${entity?uncap_first});
    }

    @RequestMapping("/update")
    @ResponseBody
    public Boolean update(${entity} ${entity?uncap_first}){
        return ${entity?uncap_first}Service.saveOrUpdate(${entity?uncap_first});
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Boolean delete(${entity} ${entity?uncap_first}){
        return ${entity?uncap_first}Service.removeById(${entity?uncap_first}.getId());
    }
}
</#if>
